/*
 * @Author: xuwejie 1529315455@qq.com
 * @Date: 2023-11-08 09:51:45
 * @LastEditors: raoyonggang 11886335+ryg321@user.noreply.gitee.com
 * @LastEditTime: 2024-05-23 17:00:57
 * @FilePath: \my-electron\src\router\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "/",
    component: () =>
      import(/* webpackChunkName: "home" */ "../views/AboutView.vue"),
  },
  {
    path: "/corporationSetting",
    name: "corporationSetting",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/corporationSetting.vue"),
  },
  {
    path: "/setting",
    name: "setting",
    component: () =>
      import(/* webpackChunkName: "home" */ "../views/setting/index.vue"),
  },
];

const router = new VueRouter({
  routes,
});
router.beforeEach((to, from, next) => {
  if(to.name === 'corporationSetting') {
    next()
  }else {
    if(localStorage.getItem('corporationInfo')) {
      next()
    }else {
      next('/corporationSetting')
    }
  }
})
const originPush = VueRouter.prototype.push
const originReplace = VueRouter.prototype.replace

//增强push，用于解决编程式路由导航重复跳转出错的问题
VueRouter.prototype.push = function(location,okCallback,errCallback){
	if(okCallback === undefined && errCallback === undefined){
		originPush.call(this,location).catch(()=>{})
	}else{
		originPush.call(this,location,okCallback,errCallback)
	}
}

//增强replace，用于解决编程式路由导航重复跳转出错的问题
VueRouter.prototype.replace = function(location,okCallback,errCallback){
	if(okCallback === undefined && errCallback === undefined){
		originReplace.call(this,location).catch(()=>{})
	}else{
		originReplace.call(this,location,okCallback,errCallback)
	}
}

export default router;
